package com.jxsm.cz.service;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Record;
import com.jxsm.jfinal.core.JxDb;
import com.jxsm.jfinal.core.ServiceController;
import com.jxsm.web.aop.AuthIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author guodegen
 * @description
 * @date 2021/4/3 10:26
 */

@AuthIgnore
@ControllerBind(controllerKey = "/selectCity")
public class SelectCityService extends ServiceController {

    public void selectCity() {
        String loc_pid = this.getPara("loc_pid");
        //查询下级单位
        List<Record> areas = JxDb.find("select loc_id,loc_name,loc_pid,(select count(1) from system_loc where loc_pid=t.loc_id) kids from system_loc t where loc_pid = ? order by loc_id asc", loc_pid);
        Map<String, Object> resultMap = new HashMap<>();
        if (areas.size() != 0 ) {
            resultMap.put("success", true);
            resultMap.put("msg", "查询成功");
            resultMap.put("data",areas);
        }else{
            resultMap.put("success", false);
            resultMap.put("msg", "没有找到子单位");
        }
        this.renderJson(JSONObject.toJSONString(resultMap));
    }
}
